{extend name="common/common" /}

{block name="style"}
<style type="text/css">
.layui-form-pane .layui-form-label{
	height: 38px;
}
.layui-input.layui-unselect{
	width: 182px;
}
</style>
{/block}

{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight col-md-12">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>学籍变动</h5>
        </div>
        <div class="ibox-content col-md-8">
			<div class="layui-tab layui-tab-card">
				<ul class="layui-tab-title">
					<li class="layui-this">正常变更</li>
					<li>异常变更</li>
				</ul>
				<div class="layui-tab-content">
					<div class="layui-tab-item layui-show">
						<hr>
						<form class="layui-form layui-form-pane" action="" method="post" id="normalForm">
							<div class="layui-form-item">
								<label class="layui-form-label label-required">变动原因</label>
								<div class="layui-input-inline" style="width:182px;">
									<select name="source">
										<option value="" selected>请选择</option>
										{volist name="rollStatus" id="v"}
											{if $v.is_abnormal eq 0}
												<option value="{$v.id}">{$v.name}</option>
											{/if}
										{/volist}
									</select>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label label-required">学籍状态</label>
								<div class="layui-input-inline" style="width:182px;">
									<select name="school_roll">
										<option value="" selected>请选择</option>
										<option value="0">报名中</option>
										<option value="1">在读</option>
										<option value="2">毕业</option>
										<option value="3">休学中</option>
										<option value="4">退学</option>
									</select>
								</div>
							</div>

							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">所在学校</label>
									<div class="layui-input-block">
										<input type="text" name="school" class="layui-input layui-disabled" value="{$stInfo.school|default=''}" readonly>
										<input type="hidden" name="school_id" value="{$stInfo.school_id|default=''}" class="layui-input" readonly>
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">所在专业</label>
									<div class="layui-input-block">
										<input type="text" name="major" class="layui-input layui-disabled" value="{$stInfo.major|default=''}" readonly>
										<input type="hidden" name="major_id" value="{$stInfo.major_id|default=''}" class="layui-input" readonly>
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">所在批次</label>
									<div class="layui-input-block">
										<input type="text" name="batch" class="layui-input layui-disabled" value="{$stInfo.batch|default=''}" readonly>
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">所在班级</label>
									<div class="layui-input-block">
										<input type="text" name="class" class="layui-input layui-disabled" value="{$stInfo.class|default=''}" readonly>
									</div>
								</div>
							</div>
							<div class="layui-form-item layui-form-text">
								<label class="layui-form-label">变更备注</label>
								<div class="layui-input-block">
									<textarea class="layui-textarea" name="remark"></textarea>
								</div>
							</div>
							<div class="layui-form-item text-center">
								<input type="hidden" name="student_id" value="{$stInfo.id}">
								<input type="hidden" name="abnormal" value="0">
					            <button class="btn btn-primary" type="submit">提交</button>
							</div>
						</form>
					</div>
					<div class="layui-tab-item">
						<hr>
						<form class="layui-form layui-form-pane" action="" method="post" id="abnormalForm">
							<div class="layui-form-item">
								<label class="layui-form-label label-required">变动原因</label>
								<div class="layui-input-inline"  style="width:182px;">
									<select name="source">
										<option value="" selected>请选择</option>
										{volist name="rollStatus" id="v"}
											{if $v.is_abnormal eq 1}
												<option value="{$v.id}">{$v.name}</option>
											{/if}
										{/volist}
									</select>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label label-required">学籍状态</label>
								<div class="layui-input-inline" style="width:182px;">
									<select name="school_roll">
										<option value="" selected>请选择</option>
										<option value="0">报名中</option>
										<option value="1">在读</option>
										<option value="2">毕业</option>
										<option value="3">休学中</option>
										<option value="4">退学</option>
									</select>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">所在学校</label>
									<div class="layui-input-block">
										<input type="text" name="school" class="layui-input layui-disabled" value="{$stInfo.school|default=''}" readonly>
										<input type="hidden" name="school_id" value="{$stInfo.school_id|default=''}" class="layui-input" readonly>
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label label-required">转至学校</label>
									<div class="layui-input-inline">
										<input type="text" name="to_school" id="toSchool" class="layui-input selectSchool" readonly>
										<input type="hidden" name="to_school_id" id="toSchoolId" class="layui-input" readonly>
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">所在专业</label>
									<div class="layui-input-block">
										<input type="text" name="major" class="layui-input layui-disabled" value="{$stInfo.major|default=''}" readonly>
										<input type="hidden" name="major_id" value="{$stInfo.major_id|default=''}" class="layui-input" readonly>
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label label-required">转至专业</label>
									<div class="layui-input-inline">
										<input type="text" name="to_major" id="toMajor" class="layui-input selectSchool" readonly>
										<input type="hidden" name="to_major_id" id="toMajorId" class="layui-input" readonly>
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">所在批次</label>
									<div class="layui-input-block">
										<input type="text" name="batch" class="layui-input layui-disabled" value="{$stInfo.batch|default=''}" readonly>
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label label-required">转至批次</label>
									<div class="layui-input-inline">
										<input type="text" name="to_batch" class="layui-input">
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">所在班级</label>
									<div class="layui-input-block">
										<input type="text" name="class" class="layui-input layui-disabled" value="{$stInfo.class|default=''}" readonly>
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label label-required">转至班级</label>
									<div class="layui-input-inline">
										<input type="text" name="to_class" class="layui-input">
									</div>
								</div>
							</div>
							<div class="layui-form-item layui-form-text">
								<label class="layui-form-label">变更备注</label>
								<div class="layui-input-block">
									<textarea class="layui-textarea" name="remark"></textarea>
								</div>
							</div>
							<!-- 附加流水 -->
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">付款金额</label>
									<div class="layui-input-block">
										<input type="number" name="money" class="layui-input" value="0" >
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">订单单号</label>
									<div class="layui-input-block">
										<input id="selectOrderSn" type="text" name="order_sn" class="layui-input" readonly>
									</div>
								</div>
							</div>
							<div class="layui-form-item layui-form-text">
								<label class="layui-form-label">付款备注</label>
								<div class="layui-input-block">
									<textarea class="layui-textarea" name="money_remark"></textarea>
								</div>
							</div>
							<!-- 附加流水 -->

							<div class="layui-form-item text-center">
								<input type="hidden" id="StId" name="student_id" value="{$stInfo.id}">
								<input type="hidden" name="abnormal" value="1">
					            <button class="btn btn-primary" type="submit">提交</button>
							</div>
						</form>
					</div>
				</div>
			</div>

		</div>
	</div>
</div>

<!-- 选择专业学校 -->
<div class="laycontent" style="display: none;width: 300px;padding: 30px 15px;">
    <ul id="tree"></ul>
</div>
<!-- 选择单号 -->
<div class="laySelectOrderSnBox" style="display:none;padding:15px;">
	<div id="view"></div>
</div>
{/block}

{block name="script"}
<script>
$(function(){
	layui.use(['form','laydate','tree','element'], function(){
  		var form = layui.form,laydate = layui.laydate,element = layui.element;
  	});

	getTree();

	$(".selectSchool").on('click',function(){
		selectSchoolBox = layer.open({
			type: 1,
			title: '请选择学校专业',
			anim: 2,
			skin: 'layui-layer-molv', //加上边框
			area: ['300px', '450px'], //宽高
			content: $(".laycontent")
		});
	});

	$("#abnormalForm").on('submit',function(){
		var params = $('#abnormalForm').serialize();
		$.post('./schoolRoll',params,function(res){
			if(res.code == 1){
				layer.alert(res.msg, {title: '友情提示', icon: 1, closeBtn: 0}, function(){
                    layer.closeAll();
					window.history.back();
                });
			}else{
				layer.msg(res.msg, {anim: 6});
			}
		});
		return false;
	});
	$("#normalForm").on('submit',function(){
		var params = $('#normalForm').serialize();
		$.post('./schoolRoll',params,function(res){
			if(res.code == 1){
				layer.alert(res.msg, {title: '友情提示', icon: 1, closeBtn: 0}, function(){
                    layer.closeAll();
					window.history.back();
                });
			}else{
				layer.msg(res.msg, {anim: 6});
			}
		});
		return false;
	});

	$("#selectOrderSn").on('click',function(){
		var st_id = $("#StId").val();
		$.post("./getOrderSnByStId",{st_id:st_id},function(res){
			layui.use('laytpl', function(){
				var laytpl = layui.laytpl;
				var data = res.data;
				var getTpl = OrderInfo.innerHTML,view = document.getElementById('view');
				laytpl(getTpl).render(data, function(html){
				  view.innerHTML = html;
				});
			});
		});
		SelectOrderSnBox = layer.open({
			type: 1,
			title: '请选择订单单号',
			anim: 2,
			skin: 'layui-layer-molv', //加上边框
			area: ['800px', '450px'], //宽高
			content: $(".laySelectOrderSnBox")
		});
	});
});
function getTree(form){
    $.getJSON("{:url('product/school')}", function(res){
        layui.tree({
            elem: '#tree',
			nodes: res.data,
			click: function(node){
                nowNode = node;
				if(node.pid != 0){
					$('#toMajor').val(node.name);
					$('#toMajorId').val(node.id);
					for(var i=0;i<res.data.length;i++){
						if(node.pid == res.data[i].id){
							$('#toSchool').val(res.data[i].name);
							$('#toSchoolId').val(res.data[i].id);
						}
					}
					layer.close(selectSchoolBox);
				}
            }
        });
    });
}
function sureThisRow(sn){
	$("#selectOrderSn").val(sn);
	layer.closeAll();
}
</script>

<script id="OrderInfo" type="text/html">
  <table class="table table-hover table-bordered text-center">
  	<thead>
  		<tr>
  			<th class="text-center">订单号</th>
  			<th class="text-center">学校</th>
  			<th class="text-center">专业</th>
  			<th class="text-center">层次</th>
  			<th class="text-center">教育模式</th>
  			<th class="text-center">下单时间</th>
  		</tr>
  	</thead>
  	<tbody>
		{{#  layui.each(d, function(index, item){ }}
  		<tr ondblclick="sureThisRow({{ item.order_sn }})">
  			<td>{{ item.order_sn }}</td>
  			<td>{{ item.school }}</td>
  			<td>{{ item.major }}</td>
  			<td>{{ item.grade_name }}</td>
  			<td>{{ item.edu }}</td>
  			<td>{{ item.c_time }}</td>
  		</tr>
		{{#  }); }}
		{{#  if(d.length === 0){ }}
	      无数据
	    {{#  } }}
  	</tbody>
  </table>
</script>
{/block}
